package com.ruibang.glass.etl.handler.sl;


import com.gitee.Jmysy.binlog4j.core.BinlogEvent;
import com.gitee.Jmysy.binlog4j.core.IBinlogEventHandler;
import com.gitee.Jmysy.binlog4j.springboot.starter.annotation.BinlogSubscriber;
import com.ruibang.glass.etl.entity.SlStationCjDetail;
import com.ruibang.glass.etl.entity.SlStationD7qxDetail;
import com.ruibang.glass.etl.mapper.SlStationCjDetailMapper;
import com.ruibang.glass.etl.mapper.SlStationD7qxDetailMapper;
import org.springframework.beans.factory.annotation.Autowired;

@BinlogSubscriber(clientName = "sl")
public class SLStationD7qxDetailBinlogEventHandler implements IBinlogEventHandler<SlStationD7qxDetail> {

    @Autowired
    private SlStationD7qxDetailMapper slStationD7qxDetailMapper;

    @Override
    public void onInsert(BinlogEvent<SlStationD7qxDetail> event) {
        if(1 > slStationD7qxDetailMapper.insert(event.getData())){
            System.out.println("sl_station_d7qx_detail_2024 插入数据失败:" + event.getData());
        }else
            System.out.println("sl_station_d7qx_detail_2024 插入数据成功");
    }

    @Override
    public void onUpdate(BinlogEvent<SlStationD7qxDetail> event)  {
        if(1 > slStationD7qxDetailMapper.updateById(event.getData())){
            System.out.println("sl_station_d7qx_detail_2024 修改数据失败:" + event.getData());
            onInsert(event);
        }else
            System.out.println("sl_station_d7qx_detail_2024 更新数据成功");
    }

    @Override
    public void onDelete(BinlogEvent<SlStationD7qxDetail> event) {
        if(1 > slStationD7qxDetailMapper.deleteById(event.getData())){
            System.out.println("sl_station_d7qx_detail_2024 删除数据失败:" + event.getData());
        }else
            System.out.println("sl_station_d7qx_detail_2024 删除数据成功");
    }

    @Override
    public boolean isHandle(String database, String table) {
        return database.equals("cold1_bc2mes") && table.startsWith("sl_station_d7qx_detail");
    }
}
